package sunbao.ido.factory;


import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import sunbao.ido.proxy.IDoProxyFactory;
import sunbao.ido.proxy.InterfaceFactory;

/**
 * \* User: MeiZhongHao
 * \* Date: 2018-10-22
 * \* Time: 14:59
 * \* Description:
 * \
 */
public class IDoFactoryBean<T> implements FactoryBean<T>, InitializingBean {

    private Class<T> mapperInterface;

    @Override
    public void afterPropertiesSet() throws Exception {
        InterfaceFactory.getInstance().put(this.mapperInterface, new IDoProxyFactory(this.mapperInterface));
    }

    @Override
    public T getObject() throws Exception {
        return InterfaceFactory.getInstance().get(this.mapperInterface).newInstance();
    }

    @Override
    public Class<T> getObjectType() {
        return this.mapperInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public IDoFactoryBean(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public IDoFactoryBean() {
    }

}